package com.mic.yzzn.plc.core.control.datastructure;

import com.mic.yzzn.plc.common.instructions.basic.PLCRequestInstruction;

/**
 * Created by ASH on 16/7/18.
 * 表示以 TCP 连接方式进行通信的 PLC 的配置信息
 */
public class TCPStationConfig extends PLCStationConfig {
    /** PLC地址 */
    private String host;
    /** 端口号 */
    private int port;

    public TCPStationConfig(String host, int port, String locationNumber)
    {
        this.host = host;
        this.port = port;
        this.locationNumber = locationNumber;
    }

    @Override
    public String id()
    {
        StringBuffer stringBuffer = new StringBuffer(host);
        stringBuffer.append("-");
        stringBuffer.append(port);
        stringBuffer.append("-");
        stringBuffer.append(locationNumber);

        return stringBuffer.toString();
    }

    @Override
    public String toString()
    {
        StringBuffer buffer = new StringBuffer();
        buffer.append("host: " + host + '\n');
        buffer.append("port: " + String.valueOf(port) + '\n');
        buffer.append("locationNumber: " +locationNumber + '\n');
        buffer.append("hash: " + XMLFieldHashCode + '\n');
        buffer.append("isUpdate: " + updateTime + '\n');
        buffer.append("overDue: " + overdue + '\n');
        for (PLCRequestInstruction ins : instructionList)
        {
            buffer.append(ins.toString().substring(0, ins.toString().length()) + '\n');
        }

        return buffer.toString();
    }

    public String getHost()
    {
        return host;
    }

    public int getPort()
    {
        return port;
    }
}
